[//
    async function( kuo,Context,context){
        Context.headers["content-type"] = 'application/json;charset=UTF-8';
        let $DATA = Object.assign({},this.$DATA);
        let $features = await Kuoplus(kuo.class);
        let $THIS =  this;
        let $_GET = kuo.get;
        let $_POST = kuo.post;
        let $LANG = this.LANG();
        let $tuid = $_GET['tuid'] ?$_GET['tuid']:0;//推广uid
        let $appid  = $features['configure']['小游戏'] && $features['configure']['小游戏']['0']?$features['configure']['小游戏']['0']:"";
        let $secret  = $features['configure']['小游戏'] &&  $features['configure']['小游戏']['1']?$features['configure']['小游戏']['1']:"";
        let UID = 0;
        let $USER = null;
        let $rawData = $_POST['rawData']?$_POST['rawData']:"";
        let $encryptedData = $_POST['encryptedData']?$_POST['encryptedData']:"";
        let $iv = $_POST['iv']?$_POST['iv']:"";
        let $code = $_POST['code']?$_POST['code']:"";
        let $Security = await Mem.Get('session/'+kuo.sessionid);
        if(!$Security ){
            $Security={
                uid:0,
                code:0,
                tuid:0
            };
        }
        let $fan = await GET("https://api.weixin.qq.com/sns/jscode2session?appid="+$appid+"&secret="+$secret+"&js_code="+$code+"&grant_type=authorization_code");
        $fan = json_decode($fan);
        if($fan['errcode']){
            $DATA.code = -1;
            $DATA.data =$fan['errcode']
            $DATA.msg = $fan['errmsg']
            Context.body = JSON.stringify($DATA);
            return ;
            
        }
        let $openid = $fan['openid']?$fan['openid']:"";
        let $unionid = $fan['unionid']?$fan['unionid']:$openid;
        let $session_key = $fan['session_key'];
        $Security['openid'] = $openid;
        let $aesKey = Buffer.from($session_key,'base64');
        let $aesIV = Buffer.from($iv,'base64');
        let $aesCipher = Buffer.from($encryptedData,'base64');
        var $dataObj = null;
        try {
            var decipher = CRYPTO.createDecipheriv('aes-128-cbc', $aesKey , $aesIV);
            decipher.setAutoPadding(true);
            var decoded = decipher.update($aesCipher, 'binary', 'utf8');
            decoded += decipher.final('utf8')
            $dataObj =  json_decode(decoded);
        } catch (error) {}

        if($dataObj && $dataObj['watermark'] &&  $dataObj['watermark']['appid'] != $appid){
            $DATA.code = -1;
            $DATA.msg = $dataObj['watermark']['appid'];
            Context.body = JSON.stringify($fan);
            return ;
        }else if(!$dataObj){
            $dataObj = json_decode($rawData);
            if(!$dataObj){
                $dataObj = {
                    nickName:$openid,
                    gender:0,
                    avatarUrl:""
                };
            }  
        }
        let $db =  await db('login_weixin');
        let $user = await $db.Where( {'unionid': $unionid } ).Find();
        if( $user ){
            if($user['openidg'] == ""){
                await $db.Where( {'unionid': $unionid } ).Update( {'openidg':$openid});
            }
            $USER =  await Uid($user['uid']);
            if($USER['accountoff'] != 1){
                $DATA.code = -1;  $DATA.msg = $LANG.accountoff;Context.body = JSON.stringify($DATA);
                return ;
            }
            $Security['uid'] = $user['uid'];
            await Mem.Put("session/"+kuo.sessionid,$Security,Expiredseconds);
            await  Kuolog('userlog',$user['uid'],0, [] ,kuo.func_,kuo.class,kuo.ip);
            
            $USER['avatar'] = pichttp($USER['avatar']==""?"Tpl/login/avatar/"+($USER['id']%10)+".png":$USER['avatar']);
            $DATA.code = 1;
            $DATA.msg = $LANG.login_true;
            $DATA.data = $USER;
            $DATA.apptoken = kuo.sessionid;
            Context.body = JSON.stringify($DATA);
            return ;
        }

        if($Security.uid && $Security.uid  > 0){
            //绑定用户
            UID = $Security.uid;
            let $chaxun = await $db.Where( {'uid': UID} ).Find();
            if($chaxun){
                $DATA.code = -1;  $DATA.msg = $LANG.account_false;Context.body = JSON.stringify($DATA);
                return ;
            }

        }else{
            $user = {
                'nickname':$dataObj['nickName']?$dataObj['nickName']:$openid,
                'sex':$dataObj['gender']?$dataObj['gender']:-1,
                'headimgurl':$dataObj['avatarUrl']?$dataObj['avatarUrl']:""
            };
            let $SEX = { "-1":"1", "1":"1","2":"0"};
            UID = await $THIS.REG({
                "name":$user.nickname,
                "sex":  $SEX [$user['sex']]?$SEX [$user['sex']]:-1,
                "tou": $user.headimgurl,
                "ip":kuo.ip,
                'tuid':$tuid
            });
        }
        if(!UID || UID < 1){
            $DATA.code = -1; $DATA.msg = $LANG.uuid_error;Context.body = JSON.stringify($DATA);
            return ;
        }
        $user = {
            'openidg':$openid,
            'unionid':$unionid,
            'uid': UID
        };
        $fan = $db.Insert($user);
        if($fan){
            $Security['uid'] = $user['uid'];
            await Mem.Put("session/"+kuo.sessionid,$Security,Expiredseconds);
            await  Kuolog('userlog',$user['uid'],0, [],kuo.func_,kuo.class,kuo.ip);
            $USER = await Uid( $user['uid'] );
            $USER['avatar'] = pichttp($USER['avatar']==""?"Tpl/login/avatar/"+($USER['id']%10)+".png":$USER['avatar']);
            $DATA.code = 1;
            $DATA.msg = $LANG.reg_true;
            $DATA.data = $USER;
            $DATA.apptoken = kuo.sessionid;
            Context.body = JSON.stringify($DATA);
        }else{
            $DATA.code = -1;
            $DATA.msg = $LANG.reg_false;
            Context.body = JSON.stringify($DATA);
        }
    } 
]